import socket,os,sys,time


def jind(a,b):
    num = int(a / b *100)
    sys.stdout.write("\r")
    sys.stdout.write("%s%%" % num)
    sys.stdout.flush()
    time.sleep(0.3)

sk = socket.socket()
sk.connect(("127.1.1.1",888))

a = input('输入图片地址：')


has_int = os.stat(a).st_size  # ->  字节数量 int

has_bytes = 0

sk.sendall(bytes(str(has_int), "utf-8"))# -> a-a

recv_1 = str(sk.recv(1024),"utf-8")    #   b-b
num_bytes = 0
if recv_1 == "100":
    recv_2 = str(sk.recv(1024),"utf-8")   #c-c
    recv_bytes = int(recv_2)
    f = open(a, "rb")
    f.seek(recv_bytes)

    for line in f:
        sk.sendall(line)  # d-d
        recv_bytes += len(line)
        jind(recv_bytes,has_int)
    f.close()

if recv_1 == "101":
    f = open(a,"rb")
    for line in f:
        sk.sendall(line) #  e-e
        num_bytes += len(line)
        jind(num_bytes, has_int)
    f.close()





